using System.Threading.Tasks;
using System.Collections.Generic;

namespace RBAC.Read.Api.Application.Services
{
    /// <summary>
    /// 地理位置（经纬度）。
    /// </summary>
    public class WeatherLocation
    {
        /// <summary>纬度</summary>
        public double Lat { get; set; }
        /// <summary>经度</summary>
        public double Lon { get; set; }
    }

    /// <summary>
    /// 当前天气数据传输对象。
    /// </summary>
    public class CurrentWeatherDto
    {
        /// <summary>位置</summary>
        public WeatherLocation Location { get; set; } = new WeatherLocation();
        /// <summary>单位：metric/imperial</summary>
        public string Units { get; set; } = "metric";
        /// <summary>温度</summary>
        public double Temp { get; set; }
        /// <summary>相对湿度（%）</summary>
        public int Humidity { get; set; }
        /// <summary>风速</summary>
        public double WindSpeed { get; set; }
        /// <summary>天气主类（例：Rain）</summary>
        public string? WeatherMain { get; set; }
        /// <summary>天气描述（例：light rain）</summary>
        public string? WeatherDesc { get; set; }
    }

    /// <summary>
    /// 小时级数据点。
    /// </summary>
    public class HourlyPoint
    {
        /// <summary>Unix 时间戳（秒）</summary>
        public long Dt { get; set; }
        /// <summary>本地年份</summary>
        public int Year { get; set; }
        /// <summary>本地月份（1-12）</summary>
        public int Month { get; set; }
        /// <summary>本地日（1-31）</summary>
        public int Day { get; set; }
        /// <summary>本地小时（0-23）</summary>
        public int Hour { get; set; }
        /// <summary>温度</summary>
        public double Temp { get; set; }
        /// <summary>相对湿度（%）</summary>
        public int Humidity { get; set; }
        /// <summary>风速</summary>
        public double WindSpeed { get; set; }
        /// <summary>降水概率（0-1）</summary>
        public double Pop { get; set; }
        /// <summary>降雨量（mm/h）</summary>
        public double Rain { get; set; }
        /// <summary>天气主类（例：Rain）</summary>
        public string? WeatherMain { get; set; }
    }

    /// <summary>
    /// 小时级预报。
    /// </summary>
    public class ForecastDto
    {
        /// <summary>位置</summary>
        public WeatherLocation Location { get; set; } = new WeatherLocation();
        /// <summary>单位：metric/imperial</summary>
        public string Units { get; set; } = "metric";
        /// <summary>逐小时数据</summary>
        public List<HourlyPoint> Hourly { get; set; } = new();
    }

    /// <summary>
    /// 天气服务接口。
    /// </summary>
    public interface IWeatherService
    {
        /// <summary>
        /// 将城市名解析为经纬度。
        /// </summary>
        Task<WeatherLocation> ResolveCityAsync(string city);
        /// <summary>
        /// 获取当前天气。
        /// </summary>
        Task<CurrentWeatherDto> GetCurrentAsync(double lat, double lon, string units = "metric");
        /// <summary>
        /// 获取小时级预报（默认未来 72 小时）。
        /// </summary>
        Task<ForecastDto> GetForecastAsync(double lat, double lon, int hours = 72, string units = "metric");
    }
}
